package com.gagakuai.bpm.service.camunda.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gagakuai.bpm.dao.mapper.camunda.MyProcMapper;
import com.gagakuai.bpm.domian.dto.camunda.MyProc;
import com.gagakuai.bpm.domian.dto.camunda.MyProcDto;
import com.gagakuai.bpm.domian.dto.camunda.MyTask;
import com.gagakuai.bpm.domian.dto.camunda.TaskCommentDto;
import com.gagakuai.bpm.service.camunda.WorkFlowPageQueryInterface;
import com.gagakuai.bpm.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class WorkFlowPageQueryImpl extends ServiceImpl<MyProcMapper, MyProcDto> implements WorkFlowPageQueryInterface {

    @Override
    public List<MyProcDto> listMyProcessByPage(MyProc myProc){
//        MyProc myProc = pageRequest.getCondition();
        QueryWrapper<MyProcDto> queryWrapper = new QueryWrapper<>();

        if(StringUtils.isNotBlank(myProc.getStartUserId())){
            queryWrapper.eq("START_USER_ID_", myProc.getStartUserId());
        }

        if(StringUtils.isNotBlank(myProc.getStartTime()) && StringUtils.isNotBlank(myProc.getEndTime())){
            queryWrapper.between("START_TIME_", myProc.getStartTime(), myProc.getEndTime());
        }
        queryWrapper.orderByDesc("START_TIME_");
//        IPage<MyProcDto> page = pageRequest.buildMybatisPlusPage();
        return this.baseMapper.listProcByPage(queryWrapper);

//        return new PageData<>(iPage);
    }


    @Override
    public List<MyProcDto> listMyTaskByPage(MyTask myTask) {

        QueryWrapper<MyProcDto> queryWrapper = new QueryWrapper<>();

        if(StringUtils.isNotBlank(myTask.getStartUserId())){
            queryWrapper.eq("proc.START_USER_ID_", myTask.getStartUserId());
        }

        if(StringUtils.isNotBlank(myTask.getHandlerUserId())){
            queryWrapper.eq("task.ASSIGNEE_", myTask.getHandlerUserId());
        }

        queryWrapper.orderByDesc("proc.START_TIME_");

//        IPage<MyProcDto> page = pageRequest.buildMybatisPlusPage();
        return this.baseMapper.listTaskByPage(queryWrapper);

//        return new PageData<>(iPage);
    }

    @Override
    public List<TaskCommentDto> comment(String procId){
        return this.baseMapper.listComment(procId);
    }

    @Override
    public List<String> getMineRunningTask(String userId){
        return this.baseMapper.getMineRuningTask(userId);
    }
}
